package com.shortlink.server.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.shortlink.common.base.BasePageReqDTO;
import com.shortlink.common.base.Result;
import com.shortlink.common.base.Results;
import com.shortlink.server.dto.shortlinkmapper.ShortLinkReqDTO;
import com.shortlink.server.dto.shortlinkstats.*;
import com.shortlink.server.service.ShortLinkStatsService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 监控控制层
 *
 * @author wp
 */
@RestController
@RequiredArgsConstructor
public class ShortLinkStatsController {
    private final ShortLinkStatsService shortLinkStatsService;

    /**
     * 批量获取基础监控数据
     */
    @PostMapping("/api/stats/shortlink/base/today/batch")
    Result<List<ShortLinkTodayBaseStatsRespDTO>> batchGetShortLinkTodayBaseStats(@RequestBody List<ShortLinkReqDTO> shortLinks) {
        return Results.success(shortLinkStatsService.batchGetShortLinkTodayBaseStats(shortLinks));
    }

    /**
     * 访问单个短链接指定时间内监控数据
     */
    @GetMapping("/api/stats/shortlink/info")
    Result<ShortLinkStatsVO> signalShortLinkStats(SignalShortLinkStatsReqDTO signalShortLinkStats) {
        return Results.success(shortLinkStatsService.signalShortLinkStats(signalShortLinkStats));
    }

    /**
     * 访问单个短链接指定时间内监控访问记录数据
     */
    @GetMapping("/api/stats/shortlink/record")
    Result<IPage<ShortLinkStatsRecordVO>> signalShortLinkStatsRecord(SignalShortLinkStatsReqDTO signalShortLinkStats,
                                                                     BasePageReqDTO page) {
        return Results.success(shortLinkStatsService.signalShortLinkStatsRecord(signalShortLinkStats, page));
    }

    /**
     * 批量访问短链接指定时间内监控数据
     */
    @PostMapping("/api/stats/shortlink/info/batch")
    Result<ShortLinkStatsVO> batchShortLinkStats(@RequestBody BatchShortLinkStatsReqDTO batchShortLinkStats) {
        return Results.success(shortLinkStatsService.batchShortLinkStats(batchShortLinkStats));
    }

    /**
     * 批量访问短链接指定时间内监控访问记录数据
     */
    @PostMapping("/api/stats/shortlink/record/batch")
    Result<IPage<ShortLinkStatsRecordVO>> batchShortLinkStatsRecord(@RequestBody BatchShortLinkStatsReqDTO groupShortLinkStats,
                                                                    BasePageReqDTO page) {
        return Results.success(shortLinkStatsService.batchShortLinkStatsRecord(groupShortLinkStats, page));
    }
}
